package com.zbkj.crmeb.store.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.utils.RedisUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.utils.*;
import com.zbkj.crmeb.store.dao.CustomsRecordDao;
import com.zbkj.crmeb.store.model.*;
import com.zbkj.crmeb.store.request.*;
import com.zbkj.crmeb.store.response.*;
import com.zbkj.crmeb.store.service.*;

/**
* @author Mr.Zhang
* @description StoreProductServiceImpl 接口实现
* @date 2020-05-27
*/
@Slf4j
@Service
public class CustomsRecordServiceImpl extends ServiceImpl<CustomsRecordDao, CustomsRecord> implements CustomsRecordService {
    @Autowired
    PriceUtil priceUtil;
    @Resource
    private CustomsRecordDao customsRecordDao;
    @Autowired
    private RedisUtil redisUtil;

    private static final Logger logger = LoggerFactory.getLogger(CustomsRecordServiceImpl.class);

    /**
     * 列表
     * @param request 请求参数
     * @param pageParamRequest 分页类参数
     * @author Mr.Zhang
     * @since 2020-05-27
     * @return List<StoreProduct>
     */
    @Override
    public PageInfo<CustomsRecordResponse> getList(CustomsRecordSearchRequest request, PageParamRequest pageParamRequest) {
        //条件查询
        Page<CustomsRecord> customsRecordPage = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        List<CustomsRecord> customsRecords = customsRecordDao.queryRecordList(request);
        if(CollectionUtils.isEmpty(customsRecords)) {
            return CommonPage.copyPageInfo(customsRecordPage, new ArrayList<>());
        }
        List<CustomsRecordResponse> customsRecordResponses = customsRecords.stream().map(item -> {
            CustomsRecordResponse response = new CustomsRecordResponse();
            BeanUtils.copyProperties(item, response);
            if(!StringUtils.isEmpty(request.getKeywords())){
                response.setKeywords(request.getKeywords());
            }
            return response;
        }).collect(Collectors.toList());
        return CommonPage.copyPageInfo(customsRecordPage, customsRecordResponses);
    }

}
